﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess
{
  public  class DatHang_Info
    {
        public int ID { get; set; }
        public string TenKhachHang { get; set; }
        public string DiaChi { get; set; }
        public string Email { get; set; }
        public string SoDienThoai { get; set; }
        public string GhiChu { get; set; }
        public double TongTien { get; set; }
        public bool TrangThai { get; set; }
       

      // thêm 1 đơn đặt hàng mới


        public static int DatHang_Them(int ID, string TenKhachHang, string DiaChi, string Email, string SoDienThoai, string GhiChu, double TongTien, bool Status)
        {
            object rs = DataProvider.Instance.ExecuteNonQueryWithOutput("@ID", "sp_DatHang_Them", ID, TenKhachHang, DiaChi, Email, SoDienThoai, GhiChu, TongTien, Status);
            // DataProvider.Instance.ExecuteNonQuery("Orders_Insert", TenKhachHang, DiaChi, Email, Phone, GhiChu, TongTien, status);
            int identity = rs != null ? Convert.ToInt32(rs) : 0;
            return identity;
        }
        public static List<DatHang_Info> DatHangs_ChonTatCa()
        {
            return CBO.FillCollection<DatHang_Info>(DataProvider.Instance.ExecuteReader("sp_DatHangs_ChonTatCa"));
        }
        public static DatHang_Info DatHang_Chon(int ID)
        {
            return CBO.FillObject<DatHang_Info>(DataProvider.Instance.ExecuteReader("sp_DatHang_Chon", ID));
        }
        
        //public static bool Update(int ID, int parentID, string names, int no, int active)
        //{
        //    try
        //    {
        //        object rs = DataProvider.Instance.ExecuteNonQuery("category_update", ID, parentID, names, no, active);
        //        return true;
        //    }
        //    catch (Exception)
        //    {
        //        return false;
        //    }
        //}

        public static bool DatHang_Xoa(int ID)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("sp_DatHang_Xoa", ID);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        //public static bool DanhMuc_CapNhat_TrangThai(DatHang_Info dathang)
        //{
        //    try
        //    {
        //        object rs = DataProvider.Instance.ExecuteNonQuery("sp_DanhMuc_CapNhat_TrangThai", dathang.ID, dathang.TrangThai);
        //        return true;
        //    }
        //    catch (Exception)
        //    {
        //        return false;
        //    }
        //}

        public static List<DatHang_Info> DatHangs_TrangThai(bool trangthai)
        {
            return CBO.FillCollection<DatHang_Info>(DataProvider.Instance.ExecuteReader("sp_DatHangs_TrangThai", trangthai));
        }

        public static bool DatHang_CapNhat_TrangThai(DatHang_Info order)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_DatHang_CapNhat_TrangThai", order.ID, order.TrangThai);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
